package com.hxrd.androidprint.DBUtils;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import com.hxrd.androidprint.bean.AllDetailBean;
import com.hxrd.androidprint.bean.DetailBean;
import com.hxrd.androidprint.bean.PrintBean;
import com.hxrd.androidprint.bean.ScanCodeBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by zhang on 16/11/23.
 */
public class DBUtils {


    /**
     * 获取可写的 SQLiteDatabase
     *
     * @param context
     * @return
     */
    private static SQLiteDatabase getWriteDataBase(Context context) {
        //新建一个 OpenHelper的对象
        /**
         * 第一个参数 上下文对象
         * 第二个参数 数据库文件名
         * 第三个参数 一般为null
         * 第四个参数 数据库的版本号
         */
        DBOpenHelper helper = new DBOpenHelper(context, DBOpenHelper.DATABASE_NAME, null, 1);
        return helper.getWritableDatabase();
    }

    private static SQLiteDatabase getReadDataBase(Context context) {
        DBOpenHelper helper = new DBOpenHelper(context, DBOpenHelper.DATABASE_NAME, null, 1);
        return helper.getReadableDatabase();
    }

    /*" (Order_Code text," +
                "WMSD_Code text, " +
                "ERP_DCode text, " +
                "Shipper_Code text, " +
                "Ship_Code text, "+
                "ERP_Product_Code text, "+
                "Product_Name text, "+
                "Pack_QTY text, "+
                "FactoryName text, "+
                "WareHouse_Code text, "+
                "ScanCount text,"+
                "Plan_Outbound_Time text)"*/
    public static void insertDetail(Context context,String Order_Code, String WMSD_Code, String ERP_DCode,
                                    String Shipper_Code, String Ship_Code, String ERP_Product_Code,
                                    String Product_Name, String Pack_QTY, String FactoryName,
                                    String WareHouse_Code,String ScanCount, String Plan_Outbound_Time, String is_has_code) {
        SQLiteDatabase database = getWriteDataBase(context);
        ContentValues values = new ContentValues();
        values.put("Order_Code", Order_Code);
        values.put("WMSD_Code", WMSD_Code);
        values.put("ERP_DCode", ERP_DCode);
        values.put("Shipper_Code", Shipper_Code);
        values.put("Ship_Code", Ship_Code);
        values.put("ERP_Product_Code", ERP_Product_Code);
        values.put("Product_Name", Product_Name);
        values.put("Pack_QTY", Pack_QTY);
        values.put("FactoryName", FactoryName);
        values.put("WareHouse_Code", WareHouse_Code);
        values.put("ScanCount", ScanCount);
        values.put("Plan_Outbound_Time", Plan_Outbound_Time);
        values.put("is_has_code", is_has_code);

        database.insert(DBOpenHelper.DETAIL_TAB, null, values);
        database.close();

    }

    //"Order_Code text)"
    public static void insertSendGoodsCode(Context context, String Order_Code) {
        SQLiteDatabase database = getWriteDataBase(context);
        ContentValues values = new ContentValues();
        values.put("Order_Code", Order_Code);
        values.put("Send_State", "1");

        database.insert(DBOpenHelper.SEND_GOODS_CODE_TAB, null, values);
        database.close();
    }

    public static String querySendGoodsState(Context context,String Order_Code){
        String sendState=null;
        SQLiteDatabase database = getReadDataBase(context);
        //查询方法
        Cursor cursor = database.query(
                DBOpenHelper.SEND_GOODS_CODE_TAB, //表名
                new String[]{"Send_State"}, //要显示的键
                "Order_Code=?",  //选择判断条件
                new String[]{Order_Code},  //判断具体的值
                null,  //分组
                null,  //having参数
                null); //排序

        if(cursor.moveToNext()){
            sendState=cursor.getString(cursor.getColumnIndex("Send_State"));
        }
        //关闭游标
        cursor.close();
        //关闭数据库
        database.close();

        return sendState;
    }

    public static void updateAllSendGoodsState(Context context) {
        SQLiteDatabase database = getWriteDataBase(context);
        ContentValues values = new ContentValues();
        values.put("Send_State", "0");

        /*String whereClause = " url = ?";
        String[] whereArgs = {url};*/

        database.update(DBOpenHelper.SEND_GOODS_CODE_TAB, values, null, null);
        database.close();
    }

    public static void updateSendGoodsStateByOrderCode(Context context,String Order_Code,String Send_State) {
        SQLiteDatabase database = getWriteDataBase(context);
        ContentValues values = new ContentValues();
        values.put("Send_State", Send_State);

        String whereClause = " Order_Code = ?";
        String[] whereArgs = {Order_Code};

        database.update(DBOpenHelper.SEND_GOODS_CODE_TAB, values, whereClause, whereArgs);
        database.close();
    }

    /*"WMSD_Code text,"+
                "Product_Name text,"+
                "Duo_Count text,"+
                "San_Count text,"+
                "Send_Name text,"+
                "Order_Code text,"+
                "Car_Name text)"*/

    public static void insertPrint(Context context,String WMSD_Code, String Product_Name,String Duo_Count,
                                   String San_Count,String Send_Name,
                                   String Order_Code,String Car_Name,String ERP_DCode,String ERP_Product_Code) {
        SQLiteDatabase database = getWriteDataBase(context);
        ContentValues values = new ContentValues();
        values.put("WMSD_Code", WMSD_Code);
        values.put("Product_Name", Product_Name);
        values.put("Duo_Count", Duo_Count);
        values.put("San_Count", San_Count);
        values.put("Send_Name", Send_Name);
        values.put("Order_Code", Order_Code);
        values.put("Car_Name", Car_Name);
        values.put("ERP_DCode", ERP_DCode);
        values.put("ERP_Product_Code", ERP_Product_Code);

        database.insert(DBOpenHelper.PRINT_TAB, null, values);
        database.close();
    }

    /*"Order_Code text,"+
                "Car_Name text,"+
                "WMSD_Code text,"+
                "ERP_Product_Code text,"+
                "BackCode text,"+
                "CodeCount text,"+
                "types text)"*/
    public static void insertScanCode(Context context,String Order_Code,String Car_Name,String WMSD_Code,
                                      String ERP_Product_Code, String BackCode,String CodeCount,String types,String is_has_code) {
        SQLiteDatabase database = getWriteDataBase(context);
        ContentValues values = new ContentValues();
        values.put("Order_Code", Order_Code);
        values.put("Car_Name", Car_Name);
        values.put("WMSD_Code", WMSD_Code);
        values.put("ERP_Product_Code", ERP_Product_Code);
        values.put("BackCode", BackCode);
        values.put("CodeCount", CodeCount);
        values.put("types", types);
        values.put("is_has_code", is_has_code);

        database.insert(DBOpenHelper.SCAN_CODE_TAB, null, values);
        database.close();
    }

    /*public static List<DetailBean> queryDetail(Context context){
        List<DetailBean> detailBeanList=new ArrayList<>();
        SQLiteDatabase database = getReadDataBase(context);
        //查询方法
        Cursor cursor = database.query(
                DBOpenHelper.DETAIL_TAB, //表名
                new String[]{"WMSD_Code", "ERP_DCode", "Shipper_Code", "Ship_Code", "ERP_Product_Code",
                        "Product_Name", "Pack_QTY", "FactoryName", "WareHouse_Code","Plan_Outbound_Time"}, //要显示的键
                null,  //选择判断条件
                null,  //判断具体的值
                null,  //分组
                null,  //having参数
                null); //排序

        while (cursor.moveToNext()) {
            DetailBean bean = new DetailBean();
            bean.setWMSD_Code(cursor.getString(cursor.getColumnIndex("WMSD_Code")));
            bean.setERP_DCode(cursor.getString(cursor.getColumnIndex("ERP_DCode")));
            bean.setShipper_Code(cursor.getString(cursor.getColumnIndex("Shipper_Code")));
            bean.setShip_Code(cursor.getString(cursor.getColumnIndex("Ship_Code")));
            bean.setERP_Product_Code(cursor.getString(cursor.getColumnIndex("ERP_Product_Code")));
            bean.setProduct_Name(cursor.getString(cursor.getColumnIndex("Product_Name")));
            bean.setPack_QTY(cursor.getDouble(cursor.getColumnIndex("Pack_QTY")));
            bean.setFactoryName(cursor.getString(cursor.getColumnIndex("FactoryName")));
            bean.setWareHouse_Code(cursor.getString(cursor.getColumnIndex("WareHouse_Code")));
            bean.setPlan_Outbound_Time(cursor.getString(cursor.getColumnIndex("Plan_Outbound_Time")));

            if (bean.getWMSD_Code() != null) {
                detailBeanList.add(bean);
            }
        }
        //关闭游标
        cursor.close();
        //关闭数据库
        database.close();

        return detailBeanList;
    }*/

    /*" (Order_Code text," +
            "WMSD_Code text, " +
            "ERP_DCode text, " +
            "Shipper_Code text, " +
            "Ship_Code text, "+
            "ERP_Product_Code text, "+
            "Product_Name text, "+
            "Pack_QTY text, "+
            "FactoryName text, "+
            "WareHouse_Code text, "+
            "ScanCount text,"+
            "Plan_Outbound_Time text)"*/
    public static List<AllDetailBean> queryAllDetail(Context context){
        List<AllDetailBean> allDetailBeen=new ArrayList<>();
        SQLiteDatabase database = getReadDataBase(context);
        //查询方法
        Cursor cursor = database.query(
                DBOpenHelper.DETAIL_TAB, //表名
                new String[]{"Order_Code","WMSD_Code", "ERP_DCode", "Shipper_Code", "Ship_Code", "ERP_Product_Code",
                        "Product_Name", "Pack_QTY", "FactoryName", "WareHouse_Code", "ScanCount","Plan_Outbound_Time"}, //要显示的键
                null,  //选择判断条件
                null,  //判断具体的值
                null,  //分组
                null,  //having参数
                null); //排序

        while (cursor.moveToNext()) {
            AllDetailBean bean = new AllDetailBean();
            bean.setOrder_Code(cursor.getString(cursor.getColumnIndex("Order_Code")));
            bean.setWMSD_Code(cursor.getString(cursor.getColumnIndex("WMSD_Code")));
            bean.setERP_DCode(cursor.getString(cursor.getColumnIndex("ERP_DCode")));
            bean.setShipper_Code(cursor.getString(cursor.getColumnIndex("Shipper_Code")));
            bean.setShip_Code(cursor.getString(cursor.getColumnIndex("Ship_Code")));
            bean.setERP_Product_Code(cursor.getString(cursor.getColumnIndex("ERP_Product_Code")));
            bean.setProduct_Name(cursor.getString(cursor.getColumnIndex("Product_Name")));
            bean.setPack_QTY(cursor.getDouble(cursor.getColumnIndex("Pack_QTY")));
            bean.setFactoryName(cursor.getString(cursor.getColumnIndex("FactoryName")));
            bean.setWareHouse_Code(cursor.getString(cursor.getColumnIndex("WareHouse_Code")));
            bean.setScanCount(cursor.getString(cursor.getColumnIndex("ScanCount")));
            bean.setPlan_Outbound_Time(cursor.getString(cursor.getColumnIndex("Plan_Outbound_Time")));

            if (bean.getWMSD_Code() != null) {
                allDetailBeen.add(bean);
            }
        }
        //关闭游标
        cursor.close();
        //关闭数据库
        database.close();

        return allDetailBeen;
    }

    public static List<AllDetailBean> queryAllDetailByOrderCode(Context context, String Order_Code){
        List<AllDetailBean> allDetailBeen=new ArrayList<>();
        SQLiteDatabase database = getReadDataBase(context);
        //查询方法
        Cursor cursor = database.query(
                DBOpenHelper.DETAIL_TAB, //表名
                new String[]{"Order_Code","WMSD_Code", "ERP_DCode", "Shipper_Code", "Ship_Code", "ERP_Product_Code",
                        "Product_Name", "Pack_QTY", "FactoryName", "WareHouse_Code", "ScanCount","Plan_Outbound_Time"}, //要显示的键
                "Order_Code=?",  //选择判断条件
                new String[]{Order_Code},  //判断具体的值
                null,  //分组
                null,  //having参数
                null); //排序

        while (cursor.moveToNext()) {
            AllDetailBean bean = new AllDetailBean();
            bean.setOrder_Code(cursor.getString(cursor.getColumnIndex("Order_Code")));
            bean.setWMSD_Code(cursor.getString(cursor.getColumnIndex("WMSD_Code")));
            bean.setERP_DCode(cursor.getString(cursor.getColumnIndex("ERP_DCode")));
            bean.setShipper_Code(cursor.getString(cursor.getColumnIndex("Shipper_Code")));
            bean.setShip_Code(cursor.getString(cursor.getColumnIndex("Ship_Code")));
            bean.setERP_Product_Code(cursor.getString(cursor.getColumnIndex("ERP_Product_Code")));
            bean.setProduct_Name(cursor.getString(cursor.getColumnIndex("Product_Name")));
            bean.setPack_QTY(cursor.getDouble(cursor.getColumnIndex("Pack_QTY")));
            bean.setFactoryName(cursor.getString(cursor.getColumnIndex("FactoryName")));
            bean.setWareHouse_Code(cursor.getString(cursor.getColumnIndex("WareHouse_Code")));
            bean.setScanCount(cursor.getString(cursor.getColumnIndex("ScanCount")));
            bean.setPlan_Outbound_Time(cursor.getString(cursor.getColumnIndex("Plan_Outbound_Time")));

            if (bean.getWMSD_Code() != null) {
                allDetailBeen.add(bean);
            }
        }
        //关闭游标
        cursor.close();
        //关闭数据库
        database.close();

        return allDetailBeen;
    }

    public static String queryDetailScanCount(Context context,String WMSD_Code){
        String scanCount=null;
        SQLiteDatabase database = getReadDataBase(context);
        //查询方法
        Cursor cursor = database.query(
                DBOpenHelper.DETAIL_TAB, //表名
                new String[]{"ScanCount"}, //要显示的键
                "WMSD_Code=?",  //选择判断条件
                new String[]{WMSD_Code},  //判断具体的值
                null,  //分组
                null,  //having参数
                null); //排序

        if(cursor.moveToNext()){
            scanCount=cursor.getString(cursor.getColumnIndex("ScanCount"));
        }
        //关闭游标
        cursor.close();
        //关闭数据库
        database.close();

        return scanCount;
    }

    /*"WMSD_Code text,"+
                "Product_Name text,"+
                "Duo_Count text,"+
                "San_Count text,"+
                "Send_Name text,"+
                "Order_Code text,"+
                "Car_Name text)"*/
    public static List<PrintBean> queryPrintByWMSDCode(Context context, String WMSD_Code){
        List<PrintBean> printBeanList=new ArrayList<>();
        SQLiteDatabase database = getReadDataBase(context);
        //查询方法
        Cursor cursor = database.query(
                DBOpenHelper.PRINT_TAB, //表名
                new String[]{"WMSD_Code","Product_Name", "Duo_Count", "San_Count", "Send_Name", "Order_Code", "Car_Name", "ERP_DCode"}, //要显示的键
                "WMSD_Code=?",  //选择判断条件
                new String[]{WMSD_Code},  //判断具体的值
                null,  //分组
                null,  //having参数
                null); //排序

        while (cursor.moveToNext()) {
            PrintBean bean = new PrintBean();
            bean.setWMSD_Code(cursor.getString(cursor.getColumnIndex("WMSD_Code")));
            bean.setProduct_Name(cursor.getString(cursor.getColumnIndex("Product_Name")));
            bean.setDuo_Count(cursor.getString(cursor.getColumnIndex("Duo_Count")));
            bean.setSan_Count(cursor.getString(cursor.getColumnIndex("San_Count")));
            bean.setSend_Name(cursor.getString(cursor.getColumnIndex("Send_Name")));
            bean.setOrder_Code(cursor.getString(cursor.getColumnIndex("Order_Code")));
            bean.setCar_Name(cursor.getString(cursor.getColumnIndex("Car_Name")));
            bean.setERP_DCode(cursor.getString(cursor.getColumnIndex("ERP_DCode")));

            if (bean.getOrder_Code() != null) {
                printBeanList.add(bean);
            }
        }
        //关闭游标
        cursor.close();
        //关闭数据库
        database.close();

        return printBeanList;
    }

    /*"WMSD_Code text,"+
                "Product_Name text,"+
                "Duo_Count text,"+
                "San_Count text,"+
                "Send_Name text,"+
                "Order_Code text,"+
                "Car_Name text)"*/
    public static List<PrintBean> queryPrintByOrderCode(Context context, String Order_Code){
        List<PrintBean> printBeanList=new ArrayList<>();
        SQLiteDatabase database = getReadDataBase(context);
        //查询方法
        Cursor cursor = database.query(
                DBOpenHelper.PRINT_TAB, //表名
                new String[]{"WMSD_Code","Product_Name", "Duo_Count", "San_Count", "Send_Name", "Order_Code", "Car_Name", "ERP_DCode", "ERP_Product_Code"}, //要显示的键
                "Order_Code=?",  //选择判断条件
                new String[]{Order_Code},  //判断具体的值
                null,  //分组
                null,  //having参数
                null); //排序

        while (cursor.moveToNext()) {
            PrintBean bean = new PrintBean();
            bean.setWMSD_Code(cursor.getString(cursor.getColumnIndex("WMSD_Code")));
            bean.setProduct_Name(cursor.getString(cursor.getColumnIndex("Product_Name")));
            bean.setDuo_Count(cursor.getString(cursor.getColumnIndex("Duo_Count")));
            bean.setSan_Count(cursor.getString(cursor.getColumnIndex("San_Count")));
            bean.setSend_Name(cursor.getString(cursor.getColumnIndex("Send_Name")));
            bean.setOrder_Code(cursor.getString(cursor.getColumnIndex("Order_Code")));
            bean.setCar_Name(cursor.getString(cursor.getColumnIndex("Car_Name")));
            bean.setERP_DCode(cursor.getString(cursor.getColumnIndex("ERP_DCode")));
            bean.setERP_Product_Code(cursor.getString(cursor.getColumnIndex("ERP_Product_Code")));

            if (bean.getOrder_Code() != null) {
                printBeanList.add(bean);
            }
        }
        //关闭游标
        cursor.close();
        //关闭数据库
        database.close();

        return printBeanList;
    }

    /*"WMSD_Code text,"+
            "Product_Name text,"+
            "Duo_Count text,"+
            "San_Count text,"+
            "Send_Name text,"+
            "Order_Code text,"+
            "Car_Name text)"*/
    public static List<PrintBean> queryPrint(Context context){
        List<PrintBean> printBeanList=new ArrayList<>();
        SQLiteDatabase database = getReadDataBase(context);
        //查询方法
        Cursor cursor = database.query(
                DBOpenHelper.PRINT_TAB, //表名
                new String[]{"WMSD_Code","Product_Name", "Duo_Count", "San_Count", "Send_Name", "Order_Code", "Car_Name", "ERP_DCode"}, //要显示的键
                null,  //选择判断条件
                null,  //判断具体的值
                null,  //分组
                null,  //having参数
                null); //排序

        while (cursor.moveToNext()) {
            PrintBean bean = new PrintBean();
            bean.setWMSD_Code(cursor.getString(cursor.getColumnIndex("WMSD_Code")));
            bean.setProduct_Name(cursor.getString(cursor.getColumnIndex("Product_Name")));
            bean.setDuo_Count(cursor.getString(cursor.getColumnIndex("Duo_Count")));
            bean.setSan_Count(cursor.getString(cursor.getColumnIndex("San_Count")));
            bean.setSend_Name(cursor.getString(cursor.getColumnIndex("Send_Name")));
            bean.setOrder_Code(cursor.getString(cursor.getColumnIndex("Order_Code")));
            bean.setCar_Name(cursor.getString(cursor.getColumnIndex("Car_Name")));
            bean.setERP_DCode(cursor.getString(cursor.getColumnIndex("ERP_DCode")));

            if (bean.getOrder_Code() != null) {
                printBeanList.add(bean);
            }
        }
        //关闭游标
        cursor.close();
        //关闭数据库
        database.close();

        return printBeanList;
    }

    public static List<DetailBean> queryDetailByOrderCode(Context context, String Order_Code){
        List<DetailBean> detailBeanList=new ArrayList<>();
        SQLiteDatabase database = getReadDataBase(context);
        //查询方法
        Cursor cursor = database.query(
                DBOpenHelper.DETAIL_TAB, //表名
                new String[]{"WMSD_Code", "ERP_DCode", "Shipper_Code", "Ship_Code", "ERP_Product_Code",
                        "Product_Name", "Pack_QTY", "FactoryName", "WareHouse_Code", "ScanCount","Plan_Outbound_Time","is_has_code"}, //要显示的键
                "Order_Code=?",  //选择判断条件
                new String[]{Order_Code},  //判断具体的值
                null,  //分组
                null,  //having参数
                null); //排序

        while (cursor.moveToNext()) {
            DetailBean bean = new DetailBean();
            bean.setWMSD_Code(cursor.getString(cursor.getColumnIndex("WMSD_Code")));
            bean.setERP_DCode(cursor.getString(cursor.getColumnIndex("ERP_DCode")));
            bean.setShipper_Code(cursor.getString(cursor.getColumnIndex("Shipper_Code")));
            bean.setShip_Code(cursor.getString(cursor.getColumnIndex("Ship_Code")));
            bean.setERP_Product_Code(cursor.getString(cursor.getColumnIndex("ERP_Product_Code")));
            bean.setProduct_Name(cursor.getString(cursor.getColumnIndex("Product_Name")));
            bean.setPack_QTY(cursor.getDouble(cursor.getColumnIndex("Pack_QTY")));
            bean.setFactoryName(cursor.getString(cursor.getColumnIndex("FactoryName")));
            bean.setWareHouse_Code(cursor.getString(cursor.getColumnIndex("WareHouse_Code")));
            bean.setPlan_Outbound_Time(cursor.getString(cursor.getColumnIndex("Plan_Outbound_Time")));
            bean.setIs_has_code(cursor.getString(cursor.getColumnIndex("is_has_code")));

            if (bean.getWMSD_Code() != null) {
                detailBeanList.add(bean);
            }
        }
        //关闭游标
        cursor.close();
        //关闭数据库
        database.close();

        return detailBeanList;
    }

    public static List<String> querySendGoodsCodeByOrderCode(Context context,String Order_Code){
        List<String> sendGoodsCodeList=new ArrayList<>();
        SQLiteDatabase database = getReadDataBase(context);
        //查询方法
        Cursor cursor = database.query(
                DBOpenHelper.SEND_GOODS_CODE_TAB, //表名
                new String[]{"Order_Code"}, //要显示的键
                "Order_Code=?",  //选择判断条件
                new String[]{Order_Code},  //判断具体的值
                null,  //分组
                null,  //having参数
                null); //排序

        while (cursor.moveToNext()) {
            sendGoodsCodeList.add(cursor.getString(cursor.getColumnIndex("Order_Code")));
        }
        //关闭游标
        cursor.close();
        //关闭数据库
        database.close();

        return sendGoodsCodeList;
    }

    public static List<String> querySendGoods(Context context){
        List<String> sendGoodsCodeList=new ArrayList<>();
        SQLiteDatabase database = getReadDataBase(context);
        //查询方法
        Cursor cursor = database.query(
                DBOpenHelper.SEND_GOODS_CODE_TAB, //表名
                new String[]{"Order_Code"}, //要显示的键
                null,  //选择判断条件
                null,  //判断具体的值
                null,  //分组
                null,  //having参数
                null); //排序

        while (cursor.moveToNext()) {
            sendGoodsCodeList.add(cursor.getString(cursor.getColumnIndex("Order_Code")));
        }
        //关闭游标
        cursor.close();
        //关闭数据库
        database.close();

        return sendGoodsCodeList;
    }


    public static String queryUrl(Context context){
        String url = null;
        SQLiteDatabase database = getReadDataBase(context);
        //查询方法
        Cursor cursor = database.query(
                DBOpenHelper.CHANGE_URL, //表名
                new String[]{"url"}, //要显示的键
                null,  //选择判断条件
                null,  //判断具体的值
                null,  //分组
                null,  //having参数
                null); //排序

        while (cursor.moveToNext()) {
           
            url=cursor.getString(cursor.getColumnIndex("url"));
        }
        //关闭游标
        cursor.close();
        //关闭数据库
        database.close();

        return url;
    }

    public static void insertUrl(Context context,String url) {
        SQLiteDatabase database = getWriteDataBase(context);
        ContentValues values = new ContentValues();
        values.put("url", url);

        database.insert(DBOpenHelper.CHANGE_URL, null, values);
        database.close();
    }


    public static void updateUrl(Context context, String url,String newUrl) {
        SQLiteDatabase database = getWriteDataBase(context);
        ContentValues values = new ContentValues();
        values.put("url", newUrl);

        String whereClause = " url = ?";
        String[] whereArgs = {url};

        database.update(DBOpenHelper.CHANGE_URL, values, whereClause, whereArgs);
        database.close();
    }

    /*"Order_Code text,"+
                "Car_Name text,"+
                "WMSD_Code text,"+
                "ERP_Product_Code text,"+
                "BackCode text,"+
                CodeCount
                "types text)"*/
    public static List<ScanCodeBean> queryBackCode(Context context, String backCode){
        List<ScanCodeBean> scanCodeList=new ArrayList<>();
        SQLiteDatabase database = getReadDataBase(context);
        //查询方法
        Cursor cursor = database.query(
                DBOpenHelper.SCAN_CODE_TAB, //表名
                new String[]{"Order_Code","Car_Name","WMSD_Code","ERP_Product_Code","BackCode","CodeCount","types","is_has_code"}, //要显示的键
                "BackCode=?",  //选择判断条件
                new String[]{backCode},  //判断具体的值
                null,  //分组
                null,  //having参数
                null); //排序

        while (cursor.moveToNext()) {
            ScanCodeBean scanCodeBean=new ScanCodeBean();
            scanCodeBean.setOrder_Code(cursor.getString(cursor.getColumnIndex("Order_Code")));
            scanCodeBean.setCar_Name(cursor.getString(cursor.getColumnIndex("Car_Name")));
            scanCodeBean.setWMSD_Code(cursor.getString(cursor.getColumnIndex("WMSD_Code")));
            scanCodeBean.setERP_Product_Code(cursor.getString(cursor.getColumnIndex("ERP_Product_Code")));
            scanCodeBean.setBackCode(cursor.getString(cursor.getColumnIndex("BackCode")));
            scanCodeBean.setCodeCount(cursor.getString(cursor.getColumnIndex("CodeCount")));
            scanCodeBean.setTypes(cursor.getString(cursor.getColumnIndex("types")));
            scanCodeBean.setIs_has_code(cursor.getString(cursor.getColumnIndex("is_has_code")));

            if(scanCodeBean.getBackCode()!=null){
                scanCodeList.add(scanCodeBean);
            }
        }
        //关闭游标
        cursor.close();
        //关闭数据库
        database.close();

        return scanCodeList;
    }

    /*"Order_Code text,"+
            "Car_Name text,"+
            "WMSD_Code text,"+
            "ERP_Product_Code text,"+
            "BackCode text,"+
            CodeCount
            "types text)"*/
    public static List<ScanCodeBean> queryScanCode(Context context){
        List<ScanCodeBean> scanCodeList=new ArrayList<>();
        SQLiteDatabase database = getReadDataBase(context);
        //查询方法
        Cursor cursor = database.query(
                DBOpenHelper.SCAN_CODE_TAB, //表名
                new String[]{"Order_Code","Car_Name","WMSD_Code","ERP_Product_Code","BackCode","CodeCount","types","is_has_code"}, //要显示的键
                null,  //选择判断条件
                null,  //判断具体的值
                null,  //分组
                null,  //having参数
                null); //排序

        while (cursor.moveToNext()) {
            ScanCodeBean scanCodeBean=new ScanCodeBean();
            scanCodeBean.setOrder_Code(cursor.getString(cursor.getColumnIndex("Order_Code")));
            scanCodeBean.setCar_Name(cursor.getString(cursor.getColumnIndex("Car_Name")));
            scanCodeBean.setWMSD_Code(cursor.getString(cursor.getColumnIndex("WMSD_Code")));
            scanCodeBean.setERP_Product_Code(cursor.getString(cursor.getColumnIndex("ERP_Product_Code")));
            scanCodeBean.setBackCode(cursor.getString(cursor.getColumnIndex("BackCode")));
            scanCodeBean.setCodeCount(cursor.getString(cursor.getColumnIndex("CodeCount")));
            scanCodeBean.setTypes(cursor.getString(cursor.getColumnIndex("types")));
            scanCodeBean.setIs_has_code(cursor.getString(cursor.getColumnIndex("is_has_code")));

            if(scanCodeBean.getBackCode()!=null){
                scanCodeList.add(scanCodeBean);
            }
        }
        //关闭游标
        cursor.close();
        //关闭数据库
        database.close();

        return scanCodeList;
    }

    /*"Order_Code text,"+
            "Car_Name text,"+
            "WMSD_Code text,"+
            "ERP_Product_Code text,"+
            "BackCode text,"+
            CodeCount
            "types text)"*/
    public static List<ScanCodeBean> queryScanCodeByOrderCode(Context context, String Order_Code){
        List<ScanCodeBean> scanCodeList=new ArrayList<>();
        SQLiteDatabase database = getReadDataBase(context);
        //查询方法
        Cursor cursor = database.query(
                DBOpenHelper.SCAN_CODE_TAB, //表名
                new String[]{"Order_Code","Car_Name","WMSD_Code","ERP_Product_Code","BackCode","CodeCount","types","is_has_code"}, //要显示的键
                "Order_Code=?",  //选择判断条件
                new String[]{Order_Code},  //判断具体的值
                null,  //分组
                null,  //having参数
                null); //排序

        while (cursor.moveToNext()) {
            ScanCodeBean scanCodeBean=new ScanCodeBean();
            scanCodeBean.setOrder_Code(cursor.getString(cursor.getColumnIndex("Order_Code")));
            scanCodeBean.setCar_Name(cursor.getString(cursor.getColumnIndex("Car_Name")));
            scanCodeBean.setWMSD_Code(cursor.getString(cursor.getColumnIndex("WMSD_Code")));
            scanCodeBean.setERP_Product_Code(cursor.getString(cursor.getColumnIndex("ERP_Product_Code")));
            scanCodeBean.setBackCode(cursor.getString(cursor.getColumnIndex("BackCode")));
            scanCodeBean.setCodeCount(cursor.getString(cursor.getColumnIndex("CodeCount")));
            scanCodeBean.setTypes(cursor.getString(cursor.getColumnIndex("types")));
            scanCodeBean.setIs_has_code(cursor.getString(cursor.getColumnIndex("is_has_code")));

            if(scanCodeBean.getBackCode()!=null){
                scanCodeList.add(scanCodeBean);
            }
        }
        //关闭游标
        cursor.close();
        //关闭数据库
        database.close();

        return scanCodeList;
    }


    public static String queryPrintDuoCount(Context context,String WMSD_Code){
      String duoCount = null;
        SQLiteDatabase database = getReadDataBase(context);
        //查询方法
        Cursor cursor = database.query(
                DBOpenHelper.PRINT_TAB, //表名
                new String[]{"Duo_Count"}, //要显示的键
                "WMSD_Code=?",  //选择判断条件
                new String[]{WMSD_Code},  //判断具体的值
                null,  //分组
                null,  //having参数
                null); //排序

        while (cursor.moveToNext()) {


            if(cursor.getString(cursor.getColumnIndex("Duo_Count"))!=null){
                duoCount=cursor.getString(cursor.getColumnIndex("Duo_Count"));
            }
        }
        //关闭游标
        cursor.close();
        //关闭数据库
        database.close();

        return duoCount;
    }


    public static String queryPrintSanCount(Context context,String WMSD_Code){
        String sanCount = null;
        SQLiteDatabase database = getReadDataBase(context);
        //查询方法
        Cursor cursor = database.query(
                DBOpenHelper.PRINT_TAB, //表名
                new String[]{"San_Count"}, //要显示的键
                "WMSD_Code=?",  //选择判断条件
                new String[]{WMSD_Code},  //判断具体的值
                null,  //分组
                null,  //having参数
                null); //排序

        while (cursor.moveToNext()) {


            if(cursor.getString(cursor.getColumnIndex("San_Count"))!=null){
                sanCount=cursor.getString(cursor.getColumnIndex("San_Count"));
            }
        }
        //关闭游标
        cursor.close();
        //关闭数据库
        database.close();

        return sanCount;
    }

    public static void changeScanCount(Context context, String WMSD_Code, String ScanCount) {
        SQLiteDatabase database = getWriteDataBase(context);
        ContentValues values = new ContentValues();
        values.put("ScanCount", ScanCount);

        String whereClause = " WMSD_Code = ?";
        String[] whereArgs = {WMSD_Code};

        database.update(DBOpenHelper.DETAIL_TAB, values, whereClause, whereArgs);
        database.close();
    }

    public static void changeIsHasCode(Context context, String WMSD_Code, String is_has_code) {
        SQLiteDatabase database = getWriteDataBase(context);
        ContentValues values = new ContentValues();
        values.put("is_has_code", is_has_code);

        String whereClause = " WMSD_Code = ?";
        String[] whereArgs = {WMSD_Code};

        database.update(DBOpenHelper.DETAIL_TAB, values, whereClause, whereArgs);
        database.close();
    }


    public static void updatePrintDuoCount(Context context, String WMSD_Code, String DuoCount) {
        SQLiteDatabase database = getWriteDataBase(context);
        ContentValues values = new ContentValues();
        values.put("Duo_Count", DuoCount);

        String whereClause = " WMSD_Code = ?";
        String[] whereArgs = {WMSD_Code};

        database.update(DBOpenHelper.PRINT_TAB, values, whereClause, whereArgs);
        database.close();
    }

    public static void updatePrintSanCount(Context context, String WMSD_Code, String SanCount) {
        SQLiteDatabase database = getWriteDataBase(context);
        ContentValues values = new ContentValues();
        values.put("San_Count", SanCount);

        String whereClause = " WMSD_Code = ?";
        String[] whereArgs = {WMSD_Code};

        database.update(DBOpenHelper.PRINT_TAB, values, whereClause, whereArgs);
        database.close();
    }

    /*"Order_Code text,"+
            "Car_Name text,"+
            "WMSD_Code text,"+
            "ERP_Product_Code text,"+
            "BackCode text,"+
            "types text)"*//*
    public static List<ScanCodeBean> queryBackCode1(Context context){
        List<ScanCodeBean> scanCodeList=new ArrayList<>();
        SQLiteDatabase database = getReadDataBase(context);
        //查询方法
        Cursor cursor = database.query(
                DBOpenHelper.SCAN_CODE_TAB, //表名
                new String[]{"Order_Code","Car_Name","WMSD_Code","ERP_Product_Code","BackCode","types"}, //要显示的键
                null,  //选择判断条件
                null,  //判断具体的值
                null,  //分组
                null,  //having参数
                null); //排序

        while (cursor.moveToNext()) {
            ScanCodeBean scanCodeBean=new ScanCodeBean();
            scanCodeBean.setOrder_Code(cursor.getString(cursor.getColumnIndex("Order_Code")));
            scanCodeBean.setCar_Name(cursor.getString(cursor.getColumnIndex("Car_Name")));
            scanCodeBean.setWMSD_Code(cursor.getString(cursor.getColumnIndex("WMSD_Code")));
            scanCodeBean.setERP_Product_Code(cursor.getString(cursor.getColumnIndex("ERP_Product_Code")));
            scanCodeBean.setBackCode(cursor.getString(cursor.getColumnIndex("BackCode")));
            scanCodeBean.setTypes(cursor.getString(cursor.getColumnIndex("types")));

            if(scanCodeBean.getBackCode()!=null){
                scanCodeList.add(scanCodeBean);
            }
        }
        //关闭游标
        cursor.close();
        //关闭数据库
        database.close();

        return scanCodeList;
    }*/

    public static void deleteDetail(Context context, String Order_Code) {
        SQLiteDatabase database = getWriteDataBase(context);
        //删除的判断条件 以及 判断对应的值
        String whereClause = " Order_Code = ?";
        String[] whereArgs = {Order_Code};

        database.delete(DBOpenHelper.DETAIL_TAB, whereClause, whereArgs);
        database.close();

    }

    public static void deleteSendGoodsCode(Context context, String Order_Code) {
        SQLiteDatabase database = getWriteDataBase(context);
        //删除的判断条件 以及 判断对应的值
        String whereClause = " Order_Code = ?";
        String[] whereArgs = {Order_Code};

        database.delete(DBOpenHelper.SEND_GOODS_CODE_TAB, whereClause, whereArgs);
        database.close();

    }

    public static void deleteScanCode(Context context, String Order_Code) {
        SQLiteDatabase database = getWriteDataBase(context);
        //删除的判断条件 以及 判断对应的值
        String whereClause = " Order_Code = ?";
        String[] whereArgs = {Order_Code};

        database.delete(DBOpenHelper.SCAN_CODE_TAB, whereClause, whereArgs);
        database.close();

    }

    public static void deleteScanCodeByWMSD_Code(Context context, String WMSD_Code) {
        SQLiteDatabase database = getWriteDataBase(context);
        //删除的判断条件 以及 判断对应的值
        String whereClause = " WMSD_Code = ?";
        String[] whereArgs = {WMSD_Code};

        database.delete(DBOpenHelper.SCAN_CODE_TAB, whereClause, whereArgs);
        database.close();

    }


    public static void deletePrint(Context context, String Order_Code) {
        SQLiteDatabase database = getWriteDataBase(context);
        //删除的判断条件 以及 判断对应的值
        String whereClause = " Order_Code = ?";
        String[] whereArgs = {Order_Code};

        database.delete(DBOpenHelper.PRINT_TAB, whereClause, whereArgs);
        database.close();

    }



}
